package com.ys.controller.web.sys;

import com.bo.vo.W;
import com.ys.config.MenuId;
import com.ys.config.MyConfig;
import com.ys.entity.purchase.TcgDistribution;
import com.ys.entity.purchase.TsApi1688ToKen;
import com.ys.service.sys.CommonApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;


/**
 * 688ToKen
 */
@Controller
@RequestMapping("/web/sys/tsApi1688ToKen")
public class WebTsApi1688ToKenController {
	private static final Logger logger = LoggerFactory.getLogger(WebTsApi1688ToKenController.class);

	//1688账户
	@GetMapping("/toAccount")
	public String toAccount(Model model){
		try {
			Map<String, Object> tsApi1688ToKen = new TsApi1688ToKen()
					.addField("'ease逸思电商' accountId,'*******************' accessTokenNew,FORMAT(A.refreshTokenDate, 'yyyy-MM-dd hh:mm:ss') AS refreshTokenDateNew")
					.queryFirstMap();
			//TODO 等正式上线在修改回调地址
			String redirect_uri= MyConfig.getUrlDomain();
			String url = "https://auth.1688.com/oauth/authorize?client_id="+ MyConfig.get1688AppKey()+"&site=1688&redirect_uri="+redirect_uri+"/api/outer/1688/authcallback&state=kjecp";
			tsApi1688ToKen.put("url",url);
			//获取分类信息
			model.addAttribute("dto", tsApi1688ToKen);
			return "sys/tsApi1688ToKen/toAccount";
		}catch (Exception e) {
			logger.error("修改1688账户页面出错：",e.getMessage(),e);
			return W.error(model, e.getMessage());
		}
	}

}
